package com.own.component.common.base.entity.vo;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.own.component.common.base.entity.po.BaseWithoutMemoPo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import lombok.experimental.FieldNameConstants;

import java.io.Serializable;

/**
 * BaseWithoutMemoVo
 *
 * @author chenxueli
 * @date 2024-01-13 14:05:50
 */
@Getter
@Setter
@ToString
@NoArgsConstructor
@AllArgsConstructor
@FieldNameConstants
public abstract class BaseWithoutMemoVo<T extends BaseWithoutMemoPo> extends BaseModifiedVo<T> implements Serializable {

    @JsonIgnore
    @Schema(title = "是否删除")
    private Integer isDeleted;

    @Schema(title = "数据版本号")
    private Integer version;

    /**
     * 构造方法
     *
     * @param entity 原对象
     */
    public BaseWithoutMemoVo(@NonNull T entity) {
        super(entity);
        this.version = entity.getVersion();
        this.isDeleted = entity.getIsDeleted();
    }

    /**
     * 转po对象
     *
     * @param entity 原
     * @return po对象
     */
    @Override
    public T toPo(T entity) {
        if (entity != null) {
            entity.setVersion(this.version);
            entity.setIsDeleted(this.isDeleted);
        }
        return super.toPo(entity);
    }


}
